﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="Ornament.MVCWebFrame.Models"%>
<%@ Import Namespace="System.Collections.ObjectModel" %>
<%@ Import Namespace="Iesi.Collections.Generic" %>
<%@ Import Namespace="Ornament.MemberShip" %>

<script type="text/C#" runat="server">

    private ISet<Role> Roles;

    private ISet<Role> ExistRoles;
    protected void Page_Load(object sender, EventArgs e)
    {
        var roleDao = MemberShipContext.CurrentContext.Factory.CreateRoleDao();

        Roles = new HashedSet<Role>(roleDao.GetAll().ToArray());

        if (ViewData.ContainsKey("existRoles"))
        {
            ExistRoles = (ISet<Role>)ViewData["existRoles"];
            foreach (Role role in ExistRoles)
            {
                Roles.Remove(role);
            }
        }

    }

</script>

<script src="../../Scripts/jquery.doubleSelectBox.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">

    $(document).ready(function() {
        $("#selectbox").doubleSelectBox({
            aToB: [{ target: "#assignButton", event: "click"}],
            bToA: [{ target: "#noAssignButton", event: "click"}]
        });
    });

    function GetAssignRole() {
        var result = new Array();
        $("#lbAssignRole").children("option").each(function(i) {
            var item = {
                text: $(this).text(),
                value: $(this).val()
            };
            result.push(item);

        });
        return result;
    }  
  
</script>

<table id="selectbox">
    <tr>
        <td>
            <label for="lbNoAssignRole" style="display: block">
                全部角色</label>
            <select id="lbNoAssignRole" multiple="true" name="lbNoAssignRole" size="10" style="width: 150px;
                height: 200px">
                <%
                    foreach (var role in Roles)
                    {
                %>
                <option value="<%=role.Name %>">
                    <%=role.Name %></option>
                <%
                
                    } 
                %>
            </select>
        </td>
        <td>
            <div class="middle" style="height: 212px">
                <div>
                    <div>
                        <input type="button" id="assignButton" style="clear: both" class="ui-state-default ui-corner-all"
                            value=">>" />
                        <br />
                        <input type="button" id="noAssignButton" style="clear: both" class="ui-state-default ui-corner-all"
                            value="<<" />
                    </div>
                </div>
            </div>
        </td>
        <td>
            <label for="lbAssignRole" style="display: block">
                已经分配的角色</label>
            <select id="lbAssignRole" multiple="true" name="lbAssignRole" style="width: 150px;
                height: 200px" size="10">
                <%
                    if (ExistRoles != null)
                    {
                        foreach (var role in ExistRoles)
                        {
                %>
                    <option value="<%=role.Name %>"><%=role.Name%></option>
                <%
                
                        }
                    }
                %>
            </select>
        </td>
    </tr>
</table>
